package com.pf.log.annotation.converter;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 通用的转换类
 *
 * @author PanFei
 * @version 1.0.0
 * @createTime 2022/9/10 22:58
 */
public class SimpleConverter implements Converter {

    private String converterKey;
    private Map<String, Map<String, String>> dataDictMap;

    public SimpleConverter(String converterKey, Map<String, Map<String, String>> dataDictMap) {
        this.converterKey = converterKey;
        this.dataDictMap = dataDictMap;
    }

    @Override
    public String getDescription(String code) {
        if (dataDictMap == null || StringUtils.isBlank(code)) {
            return null;
        }
        Map<String, String> map = dataDictMap.get(converterKey);
        return map != null ? map.get(code) : null;
    }
}
